package com.tulingxueyuan.mall.modules.oms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tulingxueyuan.mall.common.api.CommonPage;
import com.tulingxueyuan.mall.common.api.CommonResult;
import com.tulingxueyuan.mall.modules.oms.model.OmsOrderReturnReason;
import com.tulingxueyuan.mall.modules.oms.service.OmsOrderReturnReasonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 退货原因表 前端控制器
 * </p>
 *
 * @author zhaofuhao
 * @since 2022-03-03
 */
@RestController
@Api(tags = "OmsOrderReturnReasonController", description = "退货原因管理")
@RequestMapping("/returnReason")
public class OmsOrderReturnReasonController {
    @Autowired
    private OmsOrderReturnReasonService orderReturnReasonService;


    @ApiOperation("分页查询全部退货原因")
    @GetMapping(value = "/list")
    @ResponseBody
    public CommonResult list(@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                               @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        Page page = orderReturnReasonService.list(pageSize, pageNum);
        return CommonResult.success(CommonPage.restPage(page));
    }
    /**
     *   添加退货原因
     *   return request({
     *     url:'/returnReason/create',
     *     method:'post',
     *     data:data
     *   })
     */
    @ApiOperation("添加退货原因")
    @PostMapping("/create")
    @ResponseBody
    public CommonResult create(@RequestBody OmsOrderReturnReason omsOrderReturnReason){
        boolean count = orderReturnReasonService.add(omsOrderReturnReason);
        if (count){
            return CommonResult.success(count);
        }
        return CommonResult.failed();

    }
    /**
     * 修改是否显示
     * return request({
     *     url:'/returnReason/update/status',
     *     method:'post',
     *     params:params
     *   })
     */
    @ApiOperation("修改是否显示退货原因")
    @PostMapping("/update/status")
    @ResponseBody
    public CommonResult updateStatus(@RequestParam(value = "status") Integer status,
                                     @RequestParam("ids") List<Long> ids){
      boolean count=  orderReturnReasonService.updateStatus(ids,status);
      if (count){
          return CommonResult.success(count);
      }
      return CommonResult.failed();
    }
    /**
     *  根据id删除
     *  return request({
     *     url:'/returnReason/delete',
     *     method:'post',
     *     params:params
     *   })
     */
    @ApiOperation("根据id删除退货原因")
    @PostMapping("/delete")
    @ResponseBody
    public CommonResult delete(@RequestParam("ids") List<Long> ids){
      boolean count=  orderReturnReasonService.removeByIds(ids);
        if (count){
            return CommonResult.success(count);

        }
        return CommonResult.failed();
    }
    /**
     * 根据id查询
     * return request({
     *     url:'/returnReason/'+id,
     *     method:'get'
     *   })
     */
    @ApiOperation("获取单个退货原因详情信息")
    @GetMapping("{id}")
    @ResponseBody
    public CommonResult getItem(@PathVariable long id){
        OmsOrderReturnReason omsOrderReturnReason = orderReturnReasonService.getById(id);
        return CommonResult.success(omsOrderReturnReason);

    }
    /**
     * 保存修改后的数据
     * return request({
     *     url:'/returnReason/update/'+id,
     *     method:'post',
     *     data:data
     *   })
     */
    @ApiOperation("保存修改退货原因")
    @PostMapping("/update/{id}")
    public CommonResult update(@PathVariable Long id, @RequestBody OmsOrderReturnReason returnReason){
        boolean b = orderReturnReasonService.updateById(returnReason);
        if (b){
            return CommonResult.success(b);
        }
        return CommonResult.failed();


    }




}

